home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * blast.c
- *
- * blast [-1] [-H] [-I<ifield>] [-D<device-file>] [size [pkts-per-pass [passes] ] ]
- *
- * Test HIPPI-FP interface output performance.
- *
- */
- #include <stdio.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/times.h>
-
- #include <sys/hippi.h>
-
- #include <sys/errno.h>
- extern int errno;
-
- static char *src_err_name[] =
- { "no error", "HIPPI sequence error", "HIPPI source lost DSIC",
- "HIPPI source timeout", "HIPPI source lost connect",
- "HIPPI connect rejection", "HIPPI interface shutdown" };
-
- #define DEVICE_FILE "/dev/hippi0"
-
- main(int argc, char *argv[] )
- {
- register int i, j;
- int fd, status;
- int len=0x200000, retv;
- int n = 500, m = 1, child, nofork=0, sendH=0, arg;
- u_long *buf;
- hippi_fp_t fphead;
- u_long d1head[6];
- u_long I = 0x00000008;
- struct tms tm_dummy;
- clock_t start_time, end_time;
- float mbytes, t;
- char *device_name = DEVICE_FILE;
-
- arg = 1;
- if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == '1' )
- nofork++,arg++;
- if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'H' )
- sendH++,arg++;
- if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'I' )
- I = strtoul( argv[arg++]+2, NULL, 16 );
- if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'D' )
- device_name = argv[arg++]+2;
- if ( argc>arg )
- len = atoi( argv[arg++] );
- if ( argc>arg )
- n = atoi( argv[arg++] );
- if ( argc>arg )
- m = atoi( argv[arg++] );
-
- if ( (len & 7) || len < 32 || n < 2 || m < 1 )
- fprintf( stderr,"blast: parameter error\n" ),exit(1);
-
- buf = memalign( 8, len );
- mpin( buf, len );
-
- printf("blast(%s): sending %d packets of length %d to I=0x%08X \
- (%d meg total)\n", device_name, n * m, len, I, n*m*len/0x100000 );
-
- srand48( time(0) );
-
- for ( i=0; i<(len+3)/4; i++ )
- if ( sendH )
- buf[ i ] = 0x48484848; /* HHHH */
- else
- buf [ i ] = mrand48();
-
- /* alternating 00000000 and FFFFFFFF .....
- buf[ i ] = (i&1) ? 0xFFFFFFFF : 0x00000000;
- */
-
- fd = open( device_name, O_WRONLY );
- if ( fd < 0 )
- perror( "blast: couldn't open hippi device" ),exit(1);
-
- /* Set ULP */
- if ( ioctl( fd, HIPIOC_BIND_ULP, 0x17 ) < 0 )
- perror( "blast: couldn't bind to ULP" ),exit(1);
-
- /* Set I-field */
- if ( ioctl( fd, HIPIOCW_I, I ) < 0 )
- perror( "blast: couldn't set I-field" );
-
- for (i=0; i<m; i++) {
-
- if ( ! nofork )
- child = ( fork() == 0 );
- else
- child = 0;
-
- /* START */
- start_time = times( &tm_dummy );
-
- for (j= ( nofork ? n : n/2 ); j > 0; j--) {
- retv = write( fd, buf, len );
- if ( retv != len ) {
- printf(
- "blast: (%s.%s) %d: write return value: %d\n",
- device_name,
- child ? "child" : "parent",
- i, retv );
- perror( "blast: trouble writing" );
- if ( retv < 0 && errno == EIO ) {
- retv = ioctl( fd, HIPIOCW_ERR );
- printf( "HIPPI error no %d %s\n",
- retv, (retv>0) ? src_err_name[retv] :
- "huh?" );
- }
- /* exit(1); */
- }
- }
-
- if ( child )
- exit(0);
- else
- wait( &status );
-
- /* END */
- end_time = times( &tm_dummy );
-
- t = (float)(end_time - start_time)/CLK_TCK;
- mbytes = (float)n * len / 0x100000;
- printf( "blast(%s): %f megabytes sent in %f s (%f MB/s)\n",
- device_name, mbytes, t, mbytes/t );
-
- }
-
- close(fd);
- }
-
-